package com.atguigu.exam;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 使用Map接口的实现类完成员工工资(姓名--工资)的摸拟：
 1)添加几条信息
 2)列出所有的员工姓名
 3列出所有员工姓名及其工资
 4)删除名叫“Tom”的员工信息
 5)输出Jack的工资，并将其工资加1000元(通过取值实现)
 6)将所有工资低于1000元的员工的工资上涨20%(通过取值实现)
 * @author xbd
 * @create 2021-05-28 22:45
 */
public class EmployeeTest {
    public static void main(String[] args) {
        HashMap map = new HashMap();
        //1)添加几条信息
        map.put("张三",500);
        map.put("李四",600);
        map.put("Tom",6000);
        map.put("王五",7000);
        map.put("Jack",8000);
        //2)列出所有的员工姓名
        Set keySet = map.keySet();
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("*************");
        // 3列出所有员工姓名及其工资
        Set entrySet = map.entrySet();
        Iterator iterator1 = entrySet.iterator();
        while (iterator1.hasNext()){
            Object obj = iterator1.next();
            Map.Entry entry = (Map.Entry)obj;
            System.out.println("员工姓名：" + entry.getKey() + "\t工资：" + entry.getValue());
        }
        //4)删除名叫“Tom”的员工信息
        map.remove("Tom");
        //5)输出Jack的工资，并将其工资加1000元(通过取值实现)
        int salaryJack = (int) map.get("Jack");
        System.out.println("Jack的工资: " + salaryJack);
        map.put("Jack",salaryJack + 1000);
        System.out.println("************************");
        Set entrySet1 = map.entrySet();
        Iterator iterator2 = entrySet1.iterator();
        while (iterator2.hasNext()){
            Object obj1 = iterator2.next();
            Map.Entry entry1 = (Map.Entry)obj1;
            System.out.println("员工姓名：" + entry1.getKey() + "\t工资：" + entry1.getValue());
        }
        System.out.println("*************************");
        // 6)将所有工资低于1000元的员工的工资上涨20%(通过取值实现)
        Set keySet1 = map.keySet();
        Iterator iterator3 = keySet1.iterator();
        while (iterator3.hasNext()){
            Object name = iterator3.next();
            int salary = (int) map.get(name);
            if(salary < 1000){
                map.put(name,salary * 1.2);
            }
        }
        System.out.println("************************");
        Set entrySet2 = map.entrySet();
        Iterator iterator4 = entrySet1.iterator();
        while (iterator4.hasNext()){
            Object obj2 = iterator4.next();
            Map.Entry entry2 = (Map.Entry)obj2;
            System.out.println("员工姓名：" + entry2.getKey() + "\t工资：" + entry2.getValue());
        }
        System.out.println("*************************");
    }
}

